<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>箭头函数</title>
    <script>
        /***
            箭头函数没有自己的this，this指向外围作用域.
            箭头函数没有对应的原型属性.
        */
        
        window.onload = function(){
            var name = "Hanley";
            var obj= {
                name:'Rose',
                that:this,
                action1:function(){
                    console.log(this);
                },
                action2:()=>{
                    console.log(this);//箭头函数中的this指向window
                },
                action3:function(){
                    return ()=>{console.log(this)}//这里的this是obj
                }
            };

            obj.action1();
            obj.action2();
            obj.action3()();


            //箭头函数没有对应的原型属性.
           var a = ()=>{};
           a.prototype;//报错

            //箭头函数不能绑定 argument
           var b = ()=>{
               console.log('arguments='+arguments);
           }
           b(1);


            //扩展,箭头函数传参
            var c = (...x) => {
                console.log(x);
            }
            c(1,2,3,4,5,6,7,8);

            //ES5 合并数组
            var arry1 = [1,2,3];
            var arry2 = [4,5,6];
            //arry1.concat(arry2);

            //ES6 合并数组;
            var arry3 = [...arry1,...arry2];

            //SET 构造函数，类似数组，元素不重复
            const ary_set = new Set();
            //add 添加元素
            //delete(index) //删除某一个元素
            //clear()//删除全部元素
            //has(ele)//判断是否存在
            //size()//获取长度
            //ary_set.keys ,ary_set.values 基本没区别，ary_set.entries() 同时包含key和value
            ary_set.add(1).add(2).add(3);
            let arry5 = Array.from(ary_set);//Set转换为数组

            //set 合并
            var set1 = new Set([1,2,3]);
            var set2 = new Set([2,3,4,5]);
            var set3 = new Set([...set1,...set2]);

            //filter()方法
            [10,22,33,5,6,8,19].filter(function(item,index,ary){
                return item > 10;
            });


            //两个set取相同的元素
            const q1 = new Set([1,2,3,5,8,88]);
            const q2 = new Set([8,88,77,99]);
            var q3 = new Set([...q1].filter((item,index) => q2.has(item)));

            [[1,2],[3,4],[5,6]].map(  ([a]) =>{return a}   );
            [[1,2],[3,4],[5,6]].map(  
                function([a]){
                    console.log(a);
                }
            );

        }

    </script>
</head>
<body>
    
</body>
</html>